export const setLocalStorageAndTime = (key,value,time) => {
    window.localStorage.setItem(key,JSON.stringify({
        data: value,
        exp: new Date().getTime() + time * 1000,
    }))

}

export const getLocalStorageAndTime = (key) => {
    // 获取data
    let data = window.localStorage.getItem(key);
    if (data == null) {
        return null;
    }
    let dataObj = JSON.parse(data)
    if (new Date().getTime() - dataObj.exp > 0) {
        window.localStorage.removeItem(key);
        console.log(key + '已过期');
        return null;
    } else {
        return dataObj.data;
    }
}

export const removeItem = (key) => {
    window.localStorage.removeItem(key);
}

export default {
    setLocalStorageAndTime,
    getLocalStorageAndTime,
    removeItem
}